package org.ypx.shared.util;

import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.ypx.db.entity.User;

/**
 * @author Yan Peixuan
 * @date 2017/3/31 17:36
 * @description
 */
public class PasswordHelper {
    private RandomNumberGenerator randomNumberGenerator =
            new SecureRandomNumberGenerator();
    private static String algorithmName = "md5";
    private static final int hashIterations = 2;

    public static User encryptPassword(User user) {
        String newPassword = new SimpleHash(
                algorithmName,
                user.getPassword(),
                ByteSource.Util.bytes("username+salt"),
                hashIterations).toHex();
        user.setPassword(newPassword);
        return user;
    }
}
